package team.archai.nexus.boot.web.handlers;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import team.archai.nexus.boot.constant.HttpEnum;
import team.archai.nexus.boot.tool.HttpUtil;
import team.archai.nexus.boot.web.response.ResultUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description: 自定义未授权错误
 * @author: lishibin
 * @create: 2020-07-11 11:00
 **/
@Component
@ConditionalOnProperty(name = "archai-nexus.auth.type", havingValue = "security")
public class AcsDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, AccessDeniedException e) {
        HttpUtil.responseJson(response, ResultUtil.out(HttpEnum.PERMISSION_DENIED));
    }
}
